https://www.nowcoder.com/questionTerminal/2c6a0a8e1d20492f92941400036e0890
#include <iostream>
#include <string>
#include<vector>
using namespace std;

int main()
{
    int n;
    string str1,str2;
    cin>>n>>str1>>str2;
    vector<string> s(n);
    int prev1=-1,prev2=-1;
    int ret=0x3f3f3f3f;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        if(s[i]==str1){
            //找prev2，并且更新prv1
            if(prev2!=-1)
            {
                ret=min(abs(i-prev2),ret);
            }
            prev1=i;
        }
        if(s[i]==str2){
            //找prev1，并且更新prv2
            if(prev1!=-1)
            {
                ret=min(abs(prev1-i),ret);
            }
            prev2=i;
        }
    }
    cout<<(ret==0x3f3f3f3f?-1:ret)<<endl;
    return 0;
}